n <- length(.anos)

Vmax <- function(V, n) {
	R <- rep(0, length(V))
	for(i in 1:length(V))
		R[i] <- max(V[i]-n, 0)
	R
}

Danos <- function(retencao, d=.danos) {
	d <- Vmax(d-retencao, 0)
	d[d != 0]
}

Anos <- function(retencao, a=.anos, d=.danos) {
	d <- Vmax(d-retencao, 0)
	a[d != 0]
}

DanosAbaixo <- function(r)  .danos - Vmax(.danos, r)
AnosAbaixo <- function(r)   .anos

PlotDanos <- function(r)
{
	T <- Anos(r)  # 0
	X <- Danos(r)  # 0
	u <- mean(Danos(r))
	dp <- sd(Danos(r))
	plot(T, X, type='points', pch='x', cex=.75,
		main=paste('Data from natural disaster - avg:',
			format(u, digits=2),
			', std dev:',
			format(dp, digits=2)),
		cex.main = .9, cex.lab = .8,
		col='blue', lwd=2,
		xlab='Years', ylab='Damage (in billions of dollars)')

#	if(r > 0) {
#		lines(c(T[1], T[length(T)]), c(r, r),
#			col='#ff00006f', lwd=2)
#		legend('topright', paste('retenção =', r),
#			lty=1,
#			col='#ff00006f', lwd=2,
#			bg='white', cex=.8)
#	}
}

TabelaFreq <- function(Dados, nclasses)
	hist(d, nclass=nclasses, plot=FALSE)$counts

